<?php
 define("MYSQL_SERVER", "localhost");
define("MYSQL_USER", "root");
define("MYSQL_PASSWORD", "");
define("MYSQL_DATABASE", "nrs1");

mysql_connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWORD) or die ('I cannot connect to the database because 1: ' . mysql_error());
mysql_select_db(MYSQL_DATABASE) or die ('I cannot connect to the database because 2: ' . mysql_error());
if(isset($_GET['format'])) {
 
//Set our variables
$format = strtolower($_GET['format']);
 

//Run our query
$result = mysql_query('SELECT * FROM netbiz_roomtype ORDER BY `roomtype_ID` DESC') or die(mysql_error());
 
//Preapre our output
if($format == 'json') {
 
$recipes = array();
while($recipe = mysql_fetch_array($result, MYSQL_ASSOC)) {
$recipes[] = array('post'=>$recipe);
}
 
$output = json_encode(array('posts' => $recipes));


 
} elseif($format == 'xml') {
 
header('Content-type: text/xml');
$outputÂ  = "<?xml version=\"1.0\"?>\n";
$output .= "<recipes>\n";
 
for($i = 0 ; $i < mysql_num_rows($result) ; $i++){
$row = mysql_fetch_assoc($result);
$output .= "<recipe> \n";
$output .= "<recipe_id>" . $row['roomtype_ID'] . "</recipe_id> \n";
$output .= "<recipe_name>" . $row['type_name'] . "</recipe_name> \n";
$output .= "<recipe_poster>" . $row['description'] . "</recipe_poster> \n";
$output .= "</recipe> \n";
}
 
$output .= "</recipes>";
 
} else {
die('Improper response format.');
}
 
//Output the output.
echo $output;


 
}
 
?>